<?php

namespace App\Http\Controllers\api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Models\Member;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use App\Models\MyLog;
use App\Models\Camel_user;
use Illuminate\Support\Facades\Cache;
use Carbon\Carbon;

require_once('function.php');
require_once('moban.php');

/*
 *   投诉建议
 */

class ComplaintController extends Controller
{

    public function complaintAdd(Request $request)
    {

        if ($request->openid) {
            $message = Input::get('message');
            $complaint = DB::table('complaint')->insert([
                [
                    'openid' => $request->openid,
                    'redfid'=>$request->id,
                    'message' => $message,
                    'phone' => $request->phone,
                    'complaint_time' => time(),
                ]
            ]);

            if ($complaint) {
                  //发送模板消息
                    $moban = new \Moban();
                    $mobanData = [
                        'keyword1' => ['value' => $request->id],
                        'keyword2' => ['value' => $message],
                        'keyword3' => ['value' => '投诉已受理，请您耐心等待结果'],
                    ];
                    $res = $moban->send($request->openid, 'yfoRk_S7pSbl0pm5zbE5cOYl4YTD0JWqvZVJ-FBXxSc', '/pages/parcel_detail/index?id='.$request->id, $request->formId, $mobanData);
                     //将回调数据写入日志
                    $mylog = new MyLog;
                    $redata = '[redid]'.$request->id.'[openid]'.$request->openid.'[err]'.$res->errmsg;
                    $mylog->setLog('投诉模板数据:'.$redata,$logPath='moban(tousu)');
                return "提交成功！";
            } else {
                return "提交失败！";
            }

        } else {

            return "参数错误！";
        }

    }



    public function phpinfo()
    {
//        $value = Cache::store('memcached')->get('wxappshop_wechat_token');
//$value = Cache::store('memcached')->get('wxappshop_wechat_token');
//        dd($value);

        //return bcrypt('camelred@.com');

//        $mem=new \Memcached();    //实例化Memcached类
//        $server=array(array('172.18.209.52',11211), );
//        $mem->addServers($server);
//        //$mem->set('name','zhangsan',600);    ////设置缓存值，有效时间3600秒，如果有效时间设置为0,则表示该缓存值永久存在的（系统重启前）
//        $key = $mem->get('wxappshop_wechat_token');
//        //dd($key);
//        //die;
//        return substr($key,7,-2);
       return DB::connection('mysql_camel_shop')->table('user')->paginate(5);

           //$userInfo =   Camel_user::paginate(15);

//        foreach ($res as $key=>$value){
//
//
//            $v['price'] = 0;
//
//
//        }





//        DB::connection('mongodb')->collection('hb_complaint')
//            ->insert([
//                [
//                    'openid' => 00000,
//                ]
//        ]);

        //return $res;


    }


}